var layer;

$(function() {
	layui.use('layer', function() {
		layer = layui.layer;
	});
	var date = getDate();

	$("#applyCreateTime").text(date);

	$("#ordersType").change(function() {
		$("#applyMoney").text($(this).val());
	})
	
	getMoneyList();
	
})

function getMoneyList() {
		$.get('http://localhost:8810/loan/app/index/getMoneyList', function(data) {
			if (data.code == 0) {
				$("#ordersType").empty();
				var str = '<option value="0" class="scvbn">0</option>';
				$.each(data.list, function(index, item) {
					str += '<option value="' + item.applyMoney + '" class="scvbn">' + item
						.applyMoney + '</option>';
				})
				$("#ordersType").append(str);
			}
		});
	}

function getCode() {
	var cmnd = $("#cmnd").val();
	if ($.trim(cmnd) == '') {
		alert("cmnd is null");
		return false;
	}
	$.get('http://localhost:8810/loan/app/getCode', {
		cmnd: cmnd
	}, function(data) {
		layer.msg(data.msg);
	});
}

function submit() {
	var date = $("#applyCreateTime").text();
	var applyMoney = $("#applyMoney").text();
	var cmnd = $("#cmnd").val();
	var code = $("#code").val();
	console.log(date)
	if (date == 'xxxx-xx-xx' || date == '') {
		alert("params is null");
		return false;
	}
	if (applyMoney == 0) {
		alert("贷款金额不能0");
		return false;
	}
	if ($.trim(cmnd) == '') {
		alert("cmnd is null");
		return false;
	}
	if ($.trim(code) == '') {
		alert("code is null");
		return false;
	}
	var param = {
		mobile: cmnd,
		code: code,
		applyMoney: applyMoney,
		date: date
	}
	$.ajax({
		url: 'http://localhost:8810/loan/app/login',
		type: 'post',
		contentType: 'application/json',
		data: JSON.stringify(param),
		success: function(data) {
			if (data.code == 0) {
				var token = data.data.token;
				var localStorage = window.localStorage; // 浏览器提供的存储空间。 根据key-value存储数据。
				localStorage.token = token;
				console.log(data)
				if(data.data.userEntity.operatorStatus == '0' || data.data.userEntity.operatorStatus == '3'){
					window.location.href= "http://h5.v1c.cc:4999/mall/VTmaster?cell=" + cmnd;
				}else{
					window.location.href = "grzx1.html";
				}
			} else {
				layer.msg(data.msg);
			}
		}
	});
}
